//
//  YSingleCollectTableViewCell.m
//  STL_ Animation
//
//  Created by dllo on 16/4/6.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "YSingleCollectTableViewCell.h"
#import "STL.h"

@interface YSingleCollectTableViewCell ()

@property (nonatomic, strong) STLImageView *listImageView;
@property (nonatomic, strong) STLLabel *titleLabel;
@property (nonatomic, strong) STLLabel *videoCountLabel;
@property (nonatomic, strong) STLLabel *inergralLabel;
@property (nonatomic, strong) STLLabel *totalViewsLabel;
@property (nonatomic, strong) STLImageView *creatorImageView;
@property (nonatomic, strong) STLLabel *nickNameLabel;
@property (nonatomic, strong) STLView *lineView;

@end

@implementation YSingleCollectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
        [self creatViews];
    }
    return self;
}

- (void)creatViews {
    self.listImageView = [[STLImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:self.listImageView];
    
    self.titleLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.titleLabel];
    
    self.videoCountLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.videoCountLabel.textColor = [UIColor colorWithRed:155 / 255.0 green:155 / 255.0 blue:155 / 255.0 alpha:1];
    self.videoCountLabel.textAlignment = NSTextAlignmentLeft;
    self.videoCountLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.videoCountLabel];
    
    self.inergralLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.inergralLabel.textColor = [UIColor colorWithRed:155 / 255.0 green:155 / 255.0 blue:155 / 255.0 alpha:1];
    self.inergralLabel.textAlignment = NSTextAlignmentLeft;
    self.inergralLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.inergralLabel];
    
    self.totalViewsLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.totalViewsLabel.textColor = [UIColor colorWithRed:155 / 255.0 green:155 / 255.0 blue:155 / 255.0 alpha:1];
    self.totalViewsLabel.textAlignment = NSTextAlignmentLeft;
    self.totalViewsLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.totalViewsLabel];
    
    self.creatorImageView = [[STLImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:self.creatorImageView];
    
    self.nickNameLabel = [[STLLabel alloc] initWithFrame:CGRectZero];
    self.nickNameLabel.textColor = [UIColor redColor];
    self.nickNameLabel.textAlignment = NSTextAlignmentRight;
    self.nickNameLabel.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.nickNameLabel];
    
    self.lineView = [[STLView alloc] initWithFrame:CGRectZero];
    self.lineView.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:155 / 255.0 blue:155 / 255.0 alpha:1];
    [self.contentView addSubview:self.lineView];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.listImageView.frame = CGRectMake(0, 0, BoundsHeight, BoundsHeight);
    
    self.titleLabel.frame = CGRectMake(BoundsHeight + 5, 5, 200, BoundsHeight * 0.27);
    
    self.videoCountLabel.frame = CGRectMake(BoundsHeight + 5, self.titleLabel.frame.origin.y + self.titleLabel.bounds.size.height + 5, 100, BoundsHeight * 0.16);
    
    self.inergralLabel.frame = CGRectMake(BoundsHeight + 5, self.videoCountLabel.origin.y + self.videoCountLabel.bounds.size.height + 5, 150, BoundsHeight * 0.16);
    
    self.totalViewsLabel.frame = CGRectMake(BoundsHeight + 5, self.inergralLabel.frame.origin.y + self.inergralLabel.bounds.size.height, 100, BoundsHeight * 0.16);
    
    self.creatorImageView.frame = CGRectMake(BoundsWidth - 40, BoundsHeight - 40, BoundsHeight * 0.16, BoundsHeight * 0.16);
    [self.creatorImageView.layer setCornerRadius:self.creatorImageView.bounds.size.width / 2];
    self.creatorImageView.layer.masksToBounds = YES;
    
    self.nickNameLabel.frame = CGRectMake(BoundsWidth - 135, BoundsHeight - 40, 90, BoundsHeight * 0.16);
    
    self.lineView.frame = CGRectMake(20, BoundsHeight - 1, BoundsWidth - 40, 1);
}

- (void)setYSingleCollectModel:(YSingleCollectModel *)ySingleCollectModel {
    _ySingleCollectModel = ySingleCollectModel;
    
    [self.listImageView sd_setImageWithURL:[NSURL URLWithString:_ySingleCollectModel.listPic] placeholderImage:[UIImage imageNamed:@"homePlace1"]];
    
    self.titleLabel.text = _ySingleCollectModel.title;
    
    NSString *videoCountStr = [NSString stringWithFormat:@"收录高清MV%@首", _ySingleCollectModel.videoCount];
    NSRange videoCount = [videoCountStr rangeOfString:[NSString stringWithFormat:@"%@", _ySingleCollectModel.videoCount]];
    NSMutableAttributedString *videoCountAttStr = [[NSMutableAttributedString alloc] initWithString:videoCountStr];
    [videoCountAttStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1] range:videoCount];
    self.videoCountLabel.attributedText = videoCountAttStr;
    
    NSString *inergralStr = [NSString stringWithFormat:@"获得积分总数:%@", _ySingleCollectModel.integral];
    NSRange inergral = [inergralStr rangeOfString:[NSString stringWithFormat:@"%@", _ySingleCollectModel.integral]];
    NSMutableAttributedString *inergralAttStr = [[NSMutableAttributedString alloc] initWithString:inergralStr];
    [inergralAttStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1] range:inergral];
    self.inergralLabel.attributedText = inergralAttStr;
    
    NSString *totalViewStr = [NSString stringWithFormat:@"播放次数:%@", _ySingleCollectModel.totalViews];
    NSRange totalViews = [totalViewStr rangeOfString:[NSString stringWithFormat:@"%@", _ySingleCollectModel.totalViews]];
    NSMutableAttributedString *totalViewAttStr = [[NSMutableAttributedString alloc] initWithString:totalViewStr];
    [totalViewAttStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1] range:totalViews];
    self.totalViewsLabel.attributedText = totalViewAttStr;
    
    [self.creatorImageView sd_setImageWithURL:[NSURL URLWithString:_ySingleCollectModel.creatorImage] placeholderImage:[UIImage imageNamed:@"homePlace1"]];
    self.nickNameLabel.text = _ySingleCollectModel.nickName;
}


@end
